
from pydantic import BaseModel, Field, root_validator

from enums.pay_enum import PayWayTypeEnum, PayWayThirdCodeEnum


class GetPayResourceModel(BaseModel):
    pay_way: PayWayTypeEnum = Field(..., description="支付方式")
    order_sn: str = Field(..., description="订单号", max_length=32)
    third_code: PayWayThirdCodeEnum = Field(None, description="第三方code,需要根据这个code去获取支付配置")

    @root_validator()
    def validate_root(cls, attrs):
        pay_way = attrs.get("pay_way")
        if pay_way in (PayWayTypeEnum.ali_app_pay, PayWayTypeEnum.ali_wap_pay, PayWayTypeEnum.ali_page_pay):
            attrs["third_code"] = PayWayThirdCodeEnum.ali
        return attrs